<script type="text/javascript">
    {literal}
        $(document).ready(function() {
            $("#fulltext").keyup(function(event){
                if(event.keyCode == 13){
                    setFulltext($('#fulltext').val(),'timesheets_fulltext')
                }
            });
        });
    {/literal}
</script>
<h2 class="pageTitle">Timesheets</h2>
{include $data.pathToError}
<div class="menu-list">
    Month: 
    <select size="1" onchange="filter('month',this.value,'timesheets_filter')">
        <option value="-1">-</option>
        {foreach from=$data.months item="month" key="i"}
            <option value="{$i}">{$month}</option>
        {/foreach}
    </select>
    Year: 
    <select size="1" onchange="filter('year',this.value,'timesheets_filter')">
        <option value="-1">-</option>
        {foreach from=$data.years item="year" key="i"}
            <option value="{$i}">{$year}</option>
        {/foreach}
    </select>
    Fulltext search: <input id="fulltext" type="text" value="{if $data.currentFulltext != ''}{$data.currentFulltext}{/if}" /><input value="Search" type="button" onclick="setFulltext($('#fulltext').val(),'timesheets_fulltext')" />
    <div style="float: right;">
        <a target="_blank" href="{$data.root}excel.php?table=timesheets">
            <img src="{$data.root}images/excel.png" title="export to excel" alt="" height="20" width="20" />
        </a>
    </div>
</div>
{if $data.currentFilter || $data.currentFulltext!=''}
    <div class="menu-list bgDark">
        <b>Current filter:</b> 
        <ul>
            {foreach $data.currentFilter as $filter => $value}
                <li>{$filter} = <i>{$value}</i> [<a href="javascript: cancelFilter('{$filter}','timesheets_filter')" class="baseLink">Cancel</a>]</li>
            {/foreach}
            {if $data.currentFulltext != ''}
                <li>Fulltext = <i>{$data.currentFulltext}</i> [<a href="javascript: cancelFulltext('timesheets_fulltext')" class="baseLink">Cancel</a>]</li>
            {/if}
        </ul>
    </div>
{/if}
<table class="list">
    <tr>
        <th style="width: 80px" ><a href="javascript: order('date','timesheets_order')"><label for="rdate">Date*</label> {if $data.currentOrder.0=="date"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th style="width: 150px" ><a href="javascript: order('client','timesheets_order')"><label for="rclient">Client*</label> {if $data.currentOrder.0=="client"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th style="width: 120px" ><a href="javascript: order('type','timesheets_order')"><label for="rtype">Type of record*</label> {if $data.currentOrder.0=="type"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th style="width: 80px" ><a href="javascript: order('amount','timesheets_order')"><label for="ramount">Amount*</label> {if $data.currentOrder.0=="amount"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th style="width: 120px" ><a href="javascript: order('tariff','timesheets_order')"><label for="rtariff">Tariff</label> {if $data.currentOrder.0=="tariff"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th style="width: 200px" ><a href="javascript: order('description','timesheets_order')"><label for="rdescription">Description*</label> {if $data.currentOrder.0=="description"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th style="width: 80px" ><a href="javascript: order('unit_price','timesheets_order')"><label for="rprice">Unit price*</label> {if $data.currentOrder.0=="unit_price"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th style="width: 150px" ><a href="javascript: order('user_id','timesheets_order')"><label for="rclient">Added by*</label> {if $data.currentOrder.0=="user_id"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        <th style="width: 20px;"></th>
        <th style="width: 20px;"></th>
    </tr>
    {assign var=counter value=1}
    {foreach $data.records as $key => $record}
        {if $counter==1}
            {assign var=bgClass value='bgDark'}
        {else}
            {assign var=bgClass value='bgLight'}
        {/if}
        <tr class="{$bgClass} row" id="row_{$record.recordId}" onclick="selectRow('{$record.recordId}','{$bgClass}')">
            {if $counter==1}
                {assign var=counter value=2}
            {else}
                {assign var=counter value=1}
            {/if}
            <td><a class="filterLink" href="javascript: filter('date','{$record.date}','timesheets_filter')">{$record.date_formated}</a></td>
            <td><a class="filterLink" href="javascript: filter('client','{$record.client}','timesheets_filter')">{$record.client_info.name}</a></td>
            <td><a class="filterLink" href="javascript: filter('type','{$record.type}','timesheets_filter')">{$record.type_info.type_of_record}</a></td>
            <td><a class="filterLink" href="javascript: filter('amount','{$record.amount}','timesheets_filter')">{$record.amount}</a></td>
            <td><a class="filterLink" href="javascript: filter('tariff','{$record.tariff}','timesheets_filter')">{$record.tariff_info.title}</a></td>
            <td>{$record.description}</td>
            <td><a class="filterLink" href="javascript: filter('unit_price','{$record.unit_price}','timesheets_filter')">{$record.unit_price}</a></td>
            <td><a class="filterLink" href="javascript: filter('user_id','{$record.user_id}','timesheets_filter')">{$record.user_info.name} {$record.user_info.surname}</a></td>
            <td>
                {if $record.taskId != 0}
                    <a target="_blank" href="{$data.root}?input=edit_task&amp;task={$record.taskId}" title="to task">
                        <img height="10" width="10" src="{$smarty.const.PATH_TO_IMAGES}arrow.png" title="to task" alt="to task" />
                    </a>
                {/if}
            </td>
            <td>
                <a href="{$data.root}?input=tsdr_more&amp;tsdr_id={$record.recordId}" target="_blank">
                    <img height="16" width="16" src="{$smarty.const.PATH_TO_IMAGES}more.png" />
                </a>
            </td>
        </tr>
    {/foreach}
</table>
<div class="menu-list">
    <span class="pager">{$data.pager}</span>
    Records per page
    <select class="pager" size="1" onchange="changeRecordsPerPage(this.value, 'timesheets_pager')">
        <option {if $smarty.session.timesheets_pager==20}selected="selected"{/if} value="20">20</option>
        <option {if $smarty.session.timesheets_pager==50}selected="selected"{/if} value="50">50</option>
        <option {if $smarty.session.timesheets_pager==100}selected="selected"{/if} value="100">100</option>
        <option {if $smarty.session.timesheets_pager==200}selected="selected"{/if} value="200">200</option>
    </select>
    Count: {$data.total_count}
    {*<span><b>Current ordering:</b> <i>{$data.currentOrder}</i> [<a class="baseLink" href="javascript: order('CLEAR','timesheets_order')">Clear ordering</a>]</span>*}
</div>